#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

typedef struct pair
{
  int key;
  int value;
}Pair;

void exchange(Pair *a,Pair *b)
{
  int keyTemp,valueTemp;

  keyTemp = a -> key;
  a -> key = b -> key;
  b -> key = keyTemp;

  valueTemp = a -> value;
  a -> value = b -> value;
  b -> value = valueTemp; 
}

int IsLess(Pair *a, Pair *b)
{
  if(a -> key < b -> key)
    return 1;

  return 0;
}

int Partition(Pair *a,int p,int r)
{
  Pair x = a[r];
  int i = p-1;
  int j = p;
  for(;j<=r-1;j++)
    {
      //      if(a[j]<x)
      if(IsLess(&a[j],&x))
        {
          i+=1;
          exchange(&a[i],&a[j]);
        }
    }
  exchange(&a[i+1],&a[r]);
  return i+1;
}

void QuickSort(Pair *a,int p,int r)
{
  int q;
  if (p<r)
    {
      q = Partition(a,p,r);
      QuickSort(a,p,q-1);
      QuickSort(a,q+1,r);
    }
}

int main() 
{ 

#ifdef FILEIO
  freopen("in.txt","r",stdin); 
  freopen("out.txt","w",stdout); 
#endif

  int N;
  int i;
  scanf("%d",&N);
  
  Pair *a = (Pair *)malloc(sizeof(Pair)*N);
  memset(a,0,sizeof(Pair)*N);

  for(i = 0;i<N;i++)
    {
      scanf("%d",&(a[i].key));
      scanf("%d",&(a[i].value));
    }
  
  QuickSort(a,0,N - 1);
  
  for(i=0;i<N;i++)
    {
      printf("%d %d\n",a[i].key,a[i].value );
    }

#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif
  
  return 0; 
} 
